import React from 'react';
import { connect } from 'dva';
import { Select } from 'antd';
const R = require('ramda');
const Option = Select.Option;

class CurrencySelect extends React.Component {
  constructor(props) {
    super(props);
  }
  componentDidMount() {
    const { dispatch } = this.props;
    dispatch({ type: 'customsInfoGenerate/getAllCurrencys' });
  }

  render() {
    const { customsInfoGenerate } = this.props;

    return (
      <Select
        showSearch
        {...R.omit(['customsInfoGenerate'])(this.props)}
        placeholder="可通过输入代码或关键字搜索"
        filterOption={(input, option) =>
          option.props.children.toLowerCase().indexOf(input.toLowerCase()) >= 0 ||
          option.props.value.toLowerCase().indexOf(input.toLowerCase()) >= 0
        }
      >
        {(R.isNil(customsInfoGenerate.currencys) ? [] : customsInfoGenerate.currencys).map(item => {
          return (
            <Option value={item.currencyName} key={item.currencyName}>
              {item.currencyName + '[' + item.currencyCode + ']' + item.currencyDesc}
            </Option>
          );
        })}
      </Select>
    );
  }
}

export default connect(({ customsInfoGenerate }) => ({ customsInfoGenerate }))(CurrencySelect);

// WEBPACK FOOTER //
// ./public/src/components/commons/CurrencySelect.js
